#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <pthread.h>
pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;

int global=100;
void *isPrime(void *arg)
{
    while(1)
    {
        pthread_rwlock_rdlock(&rw);

        // 一段朴素的代码
        if (global % 2 == 0)
            printf("%d是偶数\n", global);

        pthread_rwlock_unlock(&rw);
        sleep(1);
    }
    
}
int main(int argc, char const *argv[])
{
    pthread_t tid;
    pthread_create(&tid,NULL,isPrime,NULL);
    while(1)
    {
        pthread_rwlock_wrlock(&rw);
        global = rand() % 5000;
        printf("%d\n",global);
        pthread_rwlock_unlock(&rw);
        sleep(1);
        
    }
    return 0;
}
